﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <assert.h>

//char* my_strncpy(char* dest, const char* src, int n)
//{
//    assert(dest && src);
//    char* ret = dest;//保存原始字符串的地址,保存返回值
//    while (n)//拷贝n个字符串
//    {
//        *dest++ = *src++;
//        n--;
//    }
//    return ret;
//}
//
//
//int main()
//{
//	char arr1[] = "abcdef";
//	char arr2[20] = { 0 };
//	char* ret = my_strncpy(arr2, arr1, 5);
//	printf("%s\n", ret);
//	return 0;
//}


char* my_strncat(char* dest, char* sour, int n)
{
	assert(dest && sour);
	char* ret = dest;
	while (*dest)
	{
		dest++;
	}
	while (n)
	{
		*dest++ = *sour++;
		n--;
	}
	*dest = '\0';
	return ret;
}


int main()
{
	char arr1[] = "abcdef";
	char arr2[] = "qwer";
	char* ret = my_strncat(arr1, arr2, 3);
	printf("%s\n", ret);
	return 0;
}